define(['InputTips','InputQuickClear'],function(){
	// checkbox
	var SearchInput=function (){
		var searchInput=this;
		searchInput.$dom=$('<span data-type="searchbar"></span>');
		searchInput.$input=$('<input type="text" class="form-control" />').appendTo(searchInput.$dom);
		//data-type="search-input" data-searchlist=".addContactTools .contactList .contact" value="手机号 / 姓名" data-tips="手机号 / 姓名" data-searchtag=".name,.description,.pinyin"
		searchInput.$btn=$('<input type="button" class="form-control" data-type="search-button" />').appendTo(searchInput.$dom);
	}
	$('body').on('keyup','[data-type="searchbar"] [data-type="search-input"]',function(){
		var $clearBtn=$(this).siblings('[data-type="clear-button"]');
		var $searchList=$($(this).attr('data-searchlist'));
		var searchTag=$(this).attr('data-searchtag');
        if(!searchTag) {
            return
        }
		var keyword=$.trim($(this).value()).toLowerCase();
		var hasResult=false;
		if(keyword==''){
			$searchList.css({
				'display':''
			});
			$clearBtn.hide();
			return false;
		}else{
			$clearBtn.show();
		}
		if($searchList.length>0){
			$searchList.each(function(){
				var $searchLi=$(this);
				var myLiHasResult=false;
				if(searchTag){
					var $searchTag=$searchLi.find(searchTag);
					$searchTag.each(function(){
						if($(this).text().toLowerCase().indexOf(keyword)>=0){
							myLiHasResult=true
						}
					})
				}else{
					if($searchLi.text().toLowerCase().indexOf(keyword)>=0){
						myLiHasResult=true
					}
				}

				if(myLiHasResult){
					$searchLi.show();
					hasResult=true;
				}else{
					$searchLi.hide();
				}
			})
		}
		if(!hasResult){
			// _Tips('无搜索结果')
		}
	});
	$('body').on('click','[data-type="searchbar"] [data-type="clear-button"]',function(){
		var $searchInput=$(this).parent().children('[data-type="search-input"]');
		$searchInput.val('').keyup();
	});
	return SearchInput;
})
